# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>

pkgname=pptpd
pkgver=1.4.0
pkgrel=3
pkgdesc="Poptop server"
arch=(loong64 x86_64)
url="http://poptop.sourceforge.net/"
license=('GPL')
depends=('ppp')
backup=(etc/pptpd.conf)
validpgpkeys=('A602F7C9A42CB3B54634A8826E6470BFAE2466C0')
source=(https://downloads.sourceforge.net/sourceforge/poptop/pptpd-$pkgver.tar.gz{,.asc}
	pptpd.service
	unrecognized-opt.patch)
sha256sums=('8fcd8b8a42de2af59e9fe8cbaa9f894045c977f4d038bbd6346a8522bb7f06c0'
            'SKIP'
            'c9ba10acd0db041da079f1e3376b65f2f867b90b458a13ff228bfc76c05eb325'
            '6ccca4806367f370a001e29a9053fbdcdd43a68664691150102c4e788f1fc8dc')

build() {
  local _pppver=`pacman -Q ppp`
  _pppver=${_pppver%-*}
  _pppver=${_pppver#ppp }

  cd "$srcdir"/$pkgname-$pkgver
#  patch -p1 <"$srcdir"/unrecognized-opt.patch
  sed -i 's|AM_CONFIG_HEADER|AC_CONFIG_HEADER|g' configure.in
  autoreconf -i
  ./configure \
    --prefix=/usr \
    --libdir=/usr/lib \
    --sbindir=/usr/bin \
    --exec-prefix=/usr \
    --mandir=/usr/share/man
  sed -i "s|#define VERSION.*|#define VERSION \"${_pppver}\"|" plugins/patchlevel.h
  make
  sed -i 's|install -o root|install|g' plugins/Makefile
  sed -i 's|?=|=|g' plugins/Makefile
}

package() {
  cd "$srcdir"/$pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  mkdir -p "$pkgdir"/etc/
  echo -e "# Read man pptpd.conf, see samples in /usr/share/doc/pptpd\n# and write your pptpd configuration here" >"$pkgdir"/etc/pptpd.conf
  install -Dm0644 "$srcdir"/$pkgname.service "$pkgdir"/usr/lib/systemd/system/$pkgname.service
  mkdir -p "$pkgdir"/usr/share/doc/pptpd
  cp -a samples "$pkgdir"/usr/share/doc/pptpd/
}
